package com.ruoyi.web.economize.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.economize.domain.Economize;
import com.ruoyi.economize.service.IEconomizeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2025-07-09
 */
@RestController
@RequestMapping("/system/economize")
public class EconomizeController extends BaseController
{
    @Autowired
    private IEconomizeService economizeService;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Economize economize)
    {
        startPage();
        List<Economize> list = economizeService.selectEconomizeList(economize);
        return getDataTable(list);
    }

    @GetMapping("/getList")
    public AjaxResult getList()
    {
        List<Economize> list = economizeService.selectEconomizeList(new Economize());
        return AjaxResult.success(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Economize economize)
    {
        List<Economize> list = economizeService.selectEconomizeList(economize);
        ExcelUtil<Economize> util = new ExcelUtil<Economize>(Economize.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(economizeService.selectEconomizeById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Economize economize)
    {
        return toAjax(economizeService.insertEconomize(economize));
    }

    /**
     * 修改【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Economize economize)
    {
        return toAjax(economizeService.updateEconomize(economize));
    }

    /**
     * 删除【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(economizeService.deleteEconomizeByIds(ids));
    }

    @PostMapping("/addFile")
    public AjaxResult addFile(@RequestParam("file") MultipartFile file) throws IOException {
        return economizeService.addFile(file);
    }
}
